<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    Function.prototype.myapply = function(thisObj, arr){
      if(thisObj === null || thisObj === undefined){
        thisObj = window
      }else{
        thisObj = Object(thisObj)
      }
      
      let sym = Symbol()
      thisObj[sym] = this

      if(Array.isArray(arr)){
        return thisObj[sym](...arr)
      }else{
        throw new TypeError(arr+"不是数组")
      }
    }

    function fun(a,b){
      console.log(this)
      console.log(this.myname)
      console.log(a,b)
    }
    let obj = {
      myname:'aa'
    }
    // fun.call(obj)
    // fun()
    // fun.call(obj,1,2)
    fun.myapply(obj,[1,2])

  </script>
</body>
</html>